﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Amie
{
    public partial class FrmProductInfo : Form
    {
        public FrmProductInfo()
        {
            InitializeComponent();
        }

        private void FrmProductInfo_Shown(object sender, EventArgs e)
        {
            //Fetch the products...
            ProductManager pm = new ProductManager();
            var products = pm.Products();
            dataGridView1.DataSource = products;
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                MessageBox.Show(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {

        }

        private void BindFormFromRow(DataGridViewRow row)
        {
            txtWebAppName.Text = row.Cells["WebApplicationName"].Value.ToString();
            txtWebAppPoolName.Text = row.Cells["WebApplicationPoolName"].Value.ToString();
            txtWebAssemblyName.Text = row.Cells["WebAssemblyName"].Value.ToString();

            txtServiceName.Text = row.Cells["ServiceName"].Value.ToString();
            txtServiceAssemblyName.Text = row.Cells["ServiceAssemblyName"].Value.ToString();

            txtConStrName.Text = row.Cells["ConnectionStringName"].Value.ToString();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //Get the selected row and throw it into editing.
            var row = GetSelectedRow();
            if (row == null) return;
            BindFormFromRow(row);
        }

        private DataGridViewRow GetSelectedRow()
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                return dataGridView1.SelectedRows[0];
            }
            return null;
        }



    }
}
